<?php
$typeID = isset($typeID)?$typeID:0;
$itemID = isset($itemID)?$itemID:0;
$menuID = isset($menuID)?$menuID:0;
if($itemID==service_type::OTHER&&$menuID!=0){
	$menuDao = new DaoMenu();
	$menu = $menuDao->getOne("id='$menuID'");
}
$pageDao = new DaoPage();
$pages = $pageDao->getAll(1);
?>
<select id="change" name="menu[typeID]" >
	<option <?php if($typeID==service_type::PRODUCT) echo "selected='selected'";?> value="<?php echo service_type::PRODUCT;?>">
		<?php echo service_type::getName(service_type::PRODUCT);?>
	</option>
	<option <?php if($typeID==service_type::NEWS) echo "selected='selected'";?> value="<?php echo service_type::NEWS;?>">
		<?php echo service_type::getName(service_type::NEWS);?>
	</option>
	<option <?php if($typeID==service_type::PAGE) echo "selected='selected'";?> value="<?php echo service_type::PAGE;?>">
		<?php echo service_type::getName(service_type::PAGE);?>
	</option>
	<option <?php if($typeID==service_type::BANNER) echo "selected='selected'";?> value="<?php echo service_type::BANNER;?>">
		<?php echo service_type::getName(service_type::BANNER);?>
	</option>
	<option <?php if($typeID==service_type::SLIDE) echo "selected='selected'";?> value="<?php echo service_type::SLIDE;?>">
		<?php echo service_type::getName(service_type::SLIDE);?>
	</option>
	<option <?php if($typeID==service_type::MENU) echo "selected='selected'";?> value="<?php echo service_type::MENU;?>">
		<?php echo service_type::getName(service_type::MENU);?>
	</option>
	<option <?php if($typeID==service_type::LINKS) echo "selected='selected'";?> value="<?php echo service_type::LINKS;?>">
		<?php echo service_type::getName(service_type::LINKS);?>
	</option>
	<option <?php if($typeID==service_type::COMPANY) echo "selected='selected'";?> value="<?php echo service_type::COMPANY;?>">
		<?php echo service_type::getName(service_type::COMPANY);?>
	</option>
	<option <?php if($typeID==service_type::OTHER) echo "selected='selected'";?> value="<?php echo service_type::OTHER;?>">
		<?php echo service_type::getName(service_type::OTHER);?>
	</option>
</select>
	<div id="productItem">
		<?php echo fetch('categorySelect',array('name'=>'menu[itemID]','type'=>service_type::PRODUCT,'parentID'=>$itemID,'show'=>1));?>	
	</div>
	<div id="newsItem" style="display:none;">
		<?php echo fetch('categorySelect',array('name'=>'menu[itemID]','type'=>service_type::NEWS,'parentID'=>$itemID,'append'=>"disabled='disabled'",'show'=>1));?>
	</div>
	<div id="pageItem" style="display:none;" >
		<?php if(!empty($pages)):?>
		<select name="menu[itemID]" disabled="disabled">
			<?php foreach($pages as $page):?>
			<option <?php if($typeID==service_type::PAGE&&$itemID==$page['id']) echo "selected='selected'";?> value="<?php echo $page['id'];?>">
			<?php echo $page['title'];?>
			</option>
			<?php endforeach;?>
		</select>
		<?php else:?>
			<label>没有页面</label>
		<?php endif;?>
	</div>
	<div id="otherItem" style="display:none;">
		<input disabled="disabled" value="<?php echo isset($menu['url'])?$menu['url']:'';?>" type="text" name="menu[url]" />
	</div>

<script type="text/javascript">
$(document).ready(function(){
	$("#change").change(function(){
		type = $(this).val();
		types = [];
		types.push("<?php echo service_type::BANNER;?>","<?php echo service_type::SLIDE;?>");
		types.push("<?php echo service_type::MENU;?>","<?php echo service_type::LINKS;?>");
		types.push("<?php echo service_type::COMPANY;?>");
		if(type=="<?php echo service_type::PRODUCT;?>"){
			$("#productItem").show().find("select").removeAttr('disabled');
			$("#newsItem").hide().find("select").attr('disabled','disabled');
			$("#pageItem").hide().find("select").attr('disabled','disabled');
			$("#otherItem").hide().find("input").attr('disabled','disabled');
		}else if(type=="<?php echo service_type::NEWS;?>"){
			$("#newsItem").show().find("select").removeAttr('disabled');
			$("#productItem").hide().find("select").attr('disabled','disabled');
			$("#pageItem").hide().find("select").attr('disabled','disabled');
			$("#otherItem").hide().find("input").attr('disabled','disabled');
		}else if(type=="<?php echo service_type::PAGE;?>"){
			$("#pageItem").show().find("select").removeAttr('disabled');
			$("#productItem").hide().find("select").attr('disabled','disabled');
			$("#newsItem").hide().find("select").attr('disabled','disabled');
			$("#otherItem").hide().find("input").attr('disabled','disabled');
		}else if($.inArray(type,types)!=-1){
			$("#pageItem").hide().find("select").attr('disabled','disabled');
			$("#productItem").hide().find("select").attr('disabled','disabled');
			$("#newsItem").hide().find("select").attr('disabled','disabled');
			$("#otherItem").hide().find("input").attr('disabled','disabled');
		}else{
			$("#otherItem").show().find("input").removeAttr('disabled');
			$("#productItem").hide().find("select").attr('disabled','disabled');
			$("#newsItem").hide().find("select").attr('disabled','disabled');
			$("#pageItem").hide().find("select").attr('disabled','disabled');
		}
	});	
	$("#change").change();		
});
</script>

